<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>定位</title>
    <style>
        .father {
            width: 500px;
            height: 500px;
            background-color: rgb(236, 206, 206);
            position: relative;
        }

        .box {
            width: 200px;
            height: 100px;
            background-color: rgb(151, 151, 246);
            /* 元素不占位,后面内容上来 */
            /* position: absolute开启后默认以页面为参考标准,如果以父元素参考,父元素添加相对定位;
            子元素一般用绝对定位
            */
            position: absolute;
            right: 10px;
            top: 50px;
            /* 显示层级 */
            z-index: 1;


        }

        .box2 {
            width: 200px;
            height: 100px;
            background-color: rgb(214, 238, 133);
            position: absolute;
            right: 100px;


        }
    </style>
</head>

<body>
    <div class="father">
        <div class="box">我是紫色</div>
        <div class="box2">我是黄色</div>
    </div>
</body>

</html>